package yartiss.engine.simulation.system.schedulable;

import java.io.IOException;

import yartiss.engine.simulation.IEnergyConsumptionProfile;
import yartiss.engine.simulation.io.ITaskElement;
import yartiss.engine.simulation.io.ITaskElementVisitor;
import yartiss.engine.simulation.system.ITask;
import yartiss.engine.simulation.system.PeriodicTask;

/**
 * 
 * @author Younes Chandarli
 * 
 */
public class SimpleTask extends PeriodicTask implements ITaskElement {

	public SimpleTask(long firstRelease, long wcet, long wcee, long period,
			long deadline, int priority, IEnergyConsumptionProfile p) {
		super(firstRelease, wcet, wcee, period, deadline, priority, p);

	}

	public SimpleTask(SimpleTask task) {
		this(task.getFirstRelease(), task.getWcet(), task.getWcee(), task
				.getPeriod(), task.getDeadline(), task.getPriority(), task
				.getEnergyConsumptionProfile());
	}

	@Override
	public ITask cloneTask() {
		return new SimpleTask(this);
	}

	@Override
	public String toString() {
		return "[" + getId() + "]First release=" + getFirstRelease()
				+ "\tWCET=" + getWcet() + "\tWCEE=" + getWcee() + "\tT="
				+ getPeriod() + "\tD=" + getDeadline() + "\tP=" + getPriority();
	}

	/**
	 * Accept function for the visitable element
	 * 
	 * @throws IOException
	 */
	@Override
	public void accept(ITaskElementVisitor visitor) throws IOException {
		visitor.visitSimpleTask(this);
	}

	@Override
	public String getType() {
		return "simple";
	}

	/**
	 * Laxity of a simple task is the difference between its deadline and its
	 * worst case execution time
	 */
	@Override
	public long getLaxity() {
		return getDeadline() - getWcet();
	}

}
